//
//  BaseTabViewController.m
//  minfubaoLib
//
//  Created by 孔晓寅 on 15/11/10.
//  Copyright © 2015年 苏州鱼儿信息科技有限公司. All rights reserved.
//

#import "BaseTabViewController.h"
#import "UINavigationBar+Awesome.h"

@interface BaseTabViewController ()

@end

@implementation BaseTabViewController
@synthesize searchBar;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.extendedLayoutIncludesOpaqueBars = YES;
    self.modalPresentationCapturesStatusBarAppearance = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self.view setBackgroundColor:[utils getBackGroupColor]];
    
    self.tabBarController.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor: [UIColor whiteColor],UITextAttributeFont : [UIFont systemFontOfSize:18]};
    
    //    UIStatusBarStyleLightContent   UIBarStyleBlackTranslucent
    [self.tabBarController.navigationController.navigationBar setBarStyle:UIStatusBarStyleLightContent];//状态栏白色
    
    NSArray *viewControllerArray = [self.tabBarController.navigationController viewControllers];
    long previousViewControllerIndex = [viewControllerArray indexOfObject:self.tabBarController] - 1;
    UIViewController *previous;
    if (previousViewControllerIndex >= 0) {
        previous = [viewControllerArray objectAtIndex:previousViewControllerIndex];
        previous.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
                                                     initWithTitle:@""
                                                     style:UIBarButtonItemStylePlain
                                                     target:self
                                                     action:nil];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    [self.tabBarController.navigationController.navigationBar lt_setBackgroundColor:[utils getThemeColor]];
    [self.tabBarController.navigationController.navigationBar setShadowImage:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
//    [self.tabBarController.navigationController.navigationBar setShadowImage:nil];
//    [self.tabBarController.navigationController.navigationBar lt_reset];
}

-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 状态栏搜索框
-(void)setCustomSearchBar:(id)target placeholder:(NSString*)placeholder{
    
    searchBar = [[UITextField alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width - 220*SCALE, 66*SCALE)];
    searchBar.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
    searchBar.placeholder = @"关键字";
    searchBar.font =[UIFont systemFontOfSize:14];
    searchBar.layer.cornerRadius = 5*SCALE;
    [searchBar.layer setBorderColor:[UIColor clearColor].CGColor];//边框颜色
    [searchBar.layer setBorderWidth:1];   //边框宽度
    [searchBar.layer setMasksToBounds:YES];
    searchBar.borderStyle = UITextBorderStyleRoundedRect;
    searchBar.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;//设置其输入内容竖直居中
    searchBar.returnKeyType = UIReturnKeySearch;
    searchBar.clearButtonMode = UITextFieldViewModeWhileEditing;
    searchBar.clearsOnBeginEditing = YES;
    searchBar.textColor = [UIColor whiteColor];
//    searchBar.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 23*SCALE, 0)];
//    searchBar.leftViewMode = UITextFieldViewModeAlways;
    UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Search" ]];
    searchBar.leftView=image;
    searchBar.leftViewMode = UITextFieldViewModeAlways;
    
    searchBar.delegate = target;
    //    searchBar.placeholder = placeholder;
    UIColor *color = [UIColor whiteColor];
    searchBar.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName: color}];
    
    [self.tabBarController.navigationItem setTitleView:searchBar];
}

#pragma mark 设置左边按钮
-(void)setCustomLeftButton:(id)target action:(SEL)action img:(NSString *)imagename{
    
    UIImage *image = [UIImage imageNamed:imagename];
    UIImageView *headIcon = [[UIImageView alloc]initWithImage:image ];
    headIcon.frame = CGRectMake(0, 0, 44, 44);
    headIcon.bounds = CGRectMake(0, 0, 40, 40);
    headIcon.contentMode = UIViewContentModeScaleAspectFill;
    
    UITapGestureRecognizer *tapHeadIcon = [[UITapGestureRecognizer alloc]initWithTarget:self action:action];
    [headIcon addGestureRecognizer:tapHeadIcon];
    
    self.tabBarController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headIcon];//设置navigationbar左边按钮
}

#pragma mark 设置右边按钮
-(void)setCustomRightButton:(id)target action:(SEL)action img:(NSString *)imagename{
    
    UIImage *image = [UIImage imageNamed:imagename];
    UIImageView *headIcon = [[UIImageView alloc]initWithImage:image ];
    headIcon.frame = CGRectMake(0, 0, 44, 44);
    headIcon.bounds = CGRectMake(0, 0, 40, 40);
    headIcon.contentMode = UIViewContentModeScaleAspectFill;
    
    UITapGestureRecognizer *tapHeadIcon = [[UITapGestureRecognizer alloc]initWithTarget:self action:action];
    [headIcon addGestureRecognizer:tapHeadIcon];
    
    self.tabBarController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headIcon];//设置navigationbar左边按钮
}

#pragma mark 设置右边文字
-(void)setCustomRightText:(id)target action:(SEL)action text:(NSString *)text{
    
    UILabel *button = [utils getLabel:14 color:[utils getTextColorGray]];
    button.text = text;
    [button sizeToFit];
    button.frame = CGRectMake(0, 0, button.frame.size.width, 44);
//    button.bounds = CGRectMake(0, 0, 40, 40);
    button.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapHeadIcon = [[UITapGestureRecognizer alloc]initWithTarget:self action:action];
    [button addGestureRecognizer:tapHeadIcon];
    self.tabBarController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];//设置navigationbar左边按钮
}

@end
